package com.itshizhan.itjidancideveloper.controller.ucenter;

import com.itshizhan.itjidancideveloper.minio.MinioUtils;
import com.itshizhan.itjidancideveloper.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Objects;

@RestController()
@RequestMapping("/upload")
public class FileUploadController {
    @Autowired
    MinioUtils minioUtils;

    @PostMapping("/image")
    public Response<String> uploadImage(@RequestParam("file")MultipartFile file) throws IOException {
        String filepath = minioUtils.putObjectOfImages(file.getInputStream(), Objects.requireNonNull(file.getOriginalFilename()),file.getContentType());
        return Response.success(filepath);
    }
}
